package com.xujicheng.dingtalk;

import com.alibaba.fastjson.JSONArray;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiDepartmentListRequest;
import com.dingtalk.api.response.OapiDepartmentListResponse;
import com.taobao.api.ApiException;
import com.xujicheng.dingtalk.oauth2.DefaultDingtalkToken;
import com.xujicheng.dingtalk.oauth2.DingtalkToken;

/**
 * @author: xujicheng
 * @project dingtalk-utils
 * @packge com.xujicheng.dingtalk
 * @date: 2018/7/25 15:57
 * @description:
 */
public class Demo {

    public static void main(String[] args) throws ApiException {
        DingtalkToken dingtalkToken = new DefaultDingtalkToken("https://oapi.dingtalk.com/gettoken","ding524b3fa4c3620da4","qUzRe9gFvk5CWqEsC38Z2FOb_nobqwAZzCU38tqeOnfZgklpSISZW0HlXWN2dIMQ");
        System.out.println(dingtalkToken.getToken());
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/list");
        OapiDepartmentListRequest request = new OapiDepartmentListRequest();
        request.setId("50998737");
        request.setHttpMethod("GET");
        request.setFetchChild(true);
        OapiDepartmentListResponse response = client.execute(request, dingtalkToken.getToken());
        if(response.isSuccess()){
            System.out.println(JSONArray.toJSONString(response.getDepartment()));
        }
    }
}
